<?php
// +-------------------------
// | 框架初始化文件
// +-------------------------
namespace Framework;

/**
 * 框架引导类
 */
class Framework {
	public  static $controller;
	public  static $method;
	private static $config;

	/**
	 * 运行入口
	 * @param  void
	 */
	static public function start($config) {

		require CORE_PATH . 'common/function.php';
		require CORE_PATH . 'Controller.class.php';
		require CORE_PATH . 'Model.class.php';
		require CORE_PATH . 'Db.class.php';
		require CORE_PATH . 'View/Smarty/Smarty.class.php';
		require CORE_PATH . 'Db/Mysql.class.php';
		require_once(CORE_PATH.'/View.class.php');
		

		self::$config = $config;
		self::init_request();
		self::init_view();
		self::init_db();

		// C('index','show');
		// $row =  M('index')->getAllNews();

		
		load_controller(self::$controller, self::$method);

		$where = array('type'=>1);
		$data = array('sex'=>0, 'avatar'=>'image');

		// M('jzwwz')->where($where)->field('sex')->save($data);
		// M('jzwwz')->where($where)->field('sex')->find();
		// M('jzwwz')->select();

		$a = M('jzwwz_action')->where($where)->find();
		
		$a = M()->showTables();


		// var_dump($a);
		// $a = insert_to_array($data, array('insert'=>1), 'avatar:before');

		// $testArr =  array('id'=>1,'name'=>'gg','sex'=>'男');
		// $b = array_element_reverse($testArr, 'id', 'sex');
		// var_dump($b);
		// var_dump($a);

	}


	private function init_controller() {
		self::$controller = isset($_GET['c'] )? $_GET['c'] : 'index';
	}

	private function init_method() {
		self::$method     = isset($_GET['m'] )? $_GET['m'] : 'index';
	}

	private function init_request() {
		self::init_controller();
		self::init_method();
	}

	private function init_view() {
		\Framework\Core\View::init(self::$config['view_engine']);
	}

	private function init_db() {
		\Framework\Core\Db::init(self::$config['database']);
	}

	

}